package com.steveproject.parttimeworktree.adapter;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.steveproject.parttimeworktree.R;
import com.steveproject.parttimeworktree.entity.Part2JobEntity;
import com.steveproject.parttimeworktree.utils.ScreenUtil;

import java.util.List;

public class Part2PublicAdapter extends BaseQuickAdapter<Part2JobEntity, BaseViewHolder> {
    private Activity activity;
    private int screenWidth;
    private int intervalWidth;
    private List<Part2JobEntity> newsList;
    private int spec;


    public Part2PublicAdapter(Activity activity, List<Part2JobEntity> newsList) {
        super(R.layout.item_part2_job, newsList);
        this.activity = activity;
        screenWidth = ScreenUtil.getScreenWidth(activity);
        intervalWidth = ScreenUtil.dip2px(activity, 40);
        this.newsList = newsList;
        spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }

    @Override
    protected void convert(BaseViewHolder helper, Part2JobEntity item) {
        TextView tv_line_bg = helper.getView(R.id.tv_line_bg);
        TextView title = helper.getView(R.id.tv_title);//标题
        LinearLayout ll_unit = helper.getView(R.id.ll_unit);//右侧金额布局
        TextView tv_money = helper.getView(R.id.tv_money);//金额
        TextView tv_unit = helper.getView(R.id.tv_unit);//单位
        TextView tv_gs = helper.getView(R.id.tv_gs);//公司名字
        TextView tv_location = helper.getView(R.id.tv_location);//公司位置

        TextView tv_experience = helper.getView(R.id.tv_experience);//经验
        TextView tv_education = helper.getView(R.id.tv_education);//学历
        ImageView iv_delete = helper.getView(R.id.iv_delete);//删除对应的简历
        title.setText(item.getTitle());
        tv_money.setText(item.getMoney());
        tv_unit.setText(item.getUnit());
        tv_gs.setText(item.getGsName());
        tv_location.setText(item.getLocation());
        tv_experience.setText(item.getYear());
        tv_education.setText(item.getEducation());
        title.measure(spec, spec);
        ll_unit.measure(spec, spec);
        int maxWidth = (screenWidth - intervalWidth - ll_unit.getMeasuredWidth());
        if (title.getMeasuredWidth() >= maxWidth) {
            RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) title.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20

            linearParams.width = maxWidth;// 控件的宽强制设成30

            title.setLayoutParams(linearParams); //使设置好的布局参数应用到控件
        } else {
            RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) title.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
            linearParams.width = maxWidth;// 控件的宽强制设成30
            title.setLayoutParams(linearParams); //使设置好的布局参数应用到控件
        }
        iv_delete.setVisibility(View.GONE);
        if (helper.getPosition() == newsList.size() - 1) {
            tv_line_bg.setVisibility(View.GONE);
        } else {
            tv_line_bg.setVisibility(View.VISIBLE);
        }
    }
}
